 (function() {
		var events = [];
		$(function() {
			setTimeout(function() {
				$("#myTab a").each(function() {
					var contentId =$(this).attr("href").replace("#", "");
					if(!$(this).parent().hasClass("active")) $("#" + contentId).hide();
				});
			}, 500)
			$("#myTab a").on("click", function(e) {
				e.preventDefault();
				$("#myTab a").each(function() {
					$(this).parent().removeClass("active")
					var contentId = $(this).attr("href").replace("#", "");
					$("#" + contentId).hide().removeClass("active");
				});
				var contentId = $(this).attr("href").replace("#", "");
				$("#" + contentId).show().addClass("active");
				$(this).parent().addClass("active");
			})
		})
	})()
	
	

//1.1 业务参数变量（数据字典变量）
var itemTypeList;
var impGredList;
var busiTypeList;
var itemSourceList;
var oTable;

//初始化下拉框数据
 function initParameterList() {
	itemTypeList = getParameterService03('itemType', 'PI');
	impGredList = getParameterService03('impGred', 'PI');
	busiTypeList = getParameterService03('pyBusTyp', 'PY');
	itemSourceList = getParameterService03("itemSource","PI");
	formatterSelectControl(itemSourceList, '#itemSourceFlSec');
	formatterSelectControl(itemSourceList, '#itemSourceMpSec');
 }
$(function() {	
	 $('#startTimeFlSec').datepicker({
         autoclose: true,
         todayHighlight: true,
         format: 'yyyy-mm-dd',
         language: "zh-CN"
     }).on("changeDate", function(e) {
		var startTime = e.date;
		$('#endTimeFlSec').datepicker('setStartDate', startTime);
	});
	 $('#endTimeFlSec').datepicker({
         autoclose: true,
         todayHighlight: true,
         format: 'yyyy-mm-dd',
         language: "zh-CN"
     }).on("changeDate", function(e) {
		var endTime = e.date;
		$('#startTimeFlSec').datepicker('setEndDate', endTime);
	});
	
	 initParameterList();
	//1.初始化Table
	oTable = new TableInit();
	oTable.Init();
	$('#flowItemsTb').bootstrapTable('hideColumn', 'trfUrl');
	$('#flowItemsTb').bootstrapTable('hideColumn', 'takeChannel');
	$('#flowItemsTb').bootstrapTable('hideColumn', 'trfSysid');
	$('#flowItemsTb').bootstrapTable('hideColumn', 'itemNo');
	$('#flowItemsTb').bootstrapTable('hideColumn', 'endTime');
	
	//查询按钮
	$("#queryFlSec").click(function(){
		$("#flowItemsTb").bootstrapTable('destroy');
		oTable.Init();
		$('#flowItemsTb').bootstrapTable('hideColumn', 'trfUrl');
		$('#flowItemsTb').bootstrapTable('hideColumn', 'takeChannel');
		$('#flowItemsTb').bootstrapTable('hideColumn', 'trfSysid');
		$('#flowItemsTb').bootstrapTable('hideColumn', 'itemNo');
		$('#flowItemsTb').bootstrapTable('hideColumn', 'endTime');
		
	});
	
	//重置
	$("#resetFlSec").click(function (){
		 $("#itemNoFlSec").val(""),
		 $('#itemTitleFlSec').val(""),
		 $('#itemContentFlSec').val(""),
		 $('#regSerialFlSec').val(""),
		 $('#startTimeFlSec').val(""),
		 $('#endTimeFlSec').val(""),
		 $('#hisHandlerFlSec').val(""),
		 $('#itemSourceFlSec').val(""),
		 $('#startTimeFlSec').datepicker('setEndDate', null),
		 $('#endTimeFlSec').datepicker('setStartDate', null)
	});
	
});

//详情数据格式化
function formatterFlowDetail(value, row, index) {
	/**var d = '<div class="label label-table label-primary pointer" onclick="flowItemsDetail(\''+ index+ '\')">详情</div>'
			+'   <div class="label label-table label-primary pointer" onclick="flowItemsHandle(\''+ index+ '\')">处理</div>';
	return d;*/
    var  detail = "<a href='javascript:flowItemsDetail(\""+ index+ "\")' style=\"color: #ff6600;display:inline;\"><i class='glyphicon glyphicon-search'></i>详情</a>";
	var  handle = "<a href='javascript:flowItemsHandle(\""+ index+ "\")' style=\"color: #ff6600;display:inline;\"><i class='glyphicon glyphicon-pencil'></i>处理</a>";
    var result = "<div class=\"btn-group dropup \" style='z-index:100'>" +
            "<button type=\"button\" class=\"btn btn-primary dropdown-toggle waves-effect input-sm waves-light\" data-toggle=\"dropdown\" aria-haspopup=\"true\" aria-expanded=\"false\">操作</button>" +
            "<ul class=\"dropdown-menu dropdown-menu-left\" style='left:50px;bottom:0%;'><li>" +
            detail + handle + 
            "</li></ul>" +
            "</div>"
    return result;
}

function flowItemsDetail(index) {
	var selects = $("#flowItemsTb").bootstrapTable('getData');
	var selectedData = $.parseJSON(JSON.stringify(selects[index]));
	//selectedData.startTime = formatterJsonTime2String(selectedData.startTime);
	//selectedData.endTime = formatterJsonTime2String(selectedData.endTime);
	//selectedData.updateTime = formatterJsonTime2String(selectedData.updateTime);
	selectedData.busiType = dropDownOptionLoop(busiTypeList, selectedData.busiType);
	selectedData.itemSource = dropDownOptionLoop(itemSourceList, selectedData.itemSource);
	$('#flowForm').loadJson2DetailForm("flowForm",selectedData);
	$("#flowModal .modal-footer").hide(); //隐藏底部按钮
	$("#flowModal").modal('show'); //打开Model
}

//处理
function flowItemsHandle(index) {
	var selects = $("#flowItemsTb").bootstrapTable('getData');
	var selectedData = $.parseJSON(JSON.stringify(selects[index]));
	var url;
	if(selectedData.trfSysid=='MP'){
		//url = mpUrl + selectedData.trfUrl+"?request=PI&key="+selectedData.regSerial;
		url = mpUrl+"views/main/welcome.jsp?piUrl="+ selectedData.trfUrl+"&funcCode=MI0041&key="+selectedData.regSerial;
	}else{
		url = msUrl + selectedData.trfUrl+"?request=PI&key="+selectedData.regSerial;
	}
	
	window.open(url);
}


var TableInit = function() {
	var oTableInit = new Object();
	//初始化Table
	oTableInit.Init = function() {
		$('#flowItemsTb').bootstrapTable({
			url : baseUrl+ 'driverAction.do', //请求后台的URL（*）
			method : 'post', //请求方式（*）
			toolbar : '#toolbar', //工具条
			striped : true, //是否显示行间隔色
			cache : false, //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
			pagination : true, //是否显示分页（*）
			sortable : false, //是否启用排序
			sortOrder : "asc", //排序方式
			singleSelect: true,//单选
			queryParams : oTableInit.queryParams,//传递参数（*）
			sidePagination : "server", //分页方式：client客户端分页，server服务端分页（*）
			pageNumber : 1, //初始化加载第一页，默认第一页
			pageSize : 10, //每页的记录行数（*）
			pageList : [5, 10, 25], //可供选择的每页的行数（*）
			//search : true, //是否显示表格搜索==客户端搜索
			//strictSearch : true,
			showColumns : false, //是否显示所有的列
			showRefresh : false, //是否显示刷新按钮
			minimumCountColumns : 2, //最少允许的列数
			clickToSelect : true, //是否启用点击选中行
			//height : 500, //如果没有设置height属性，表格自动根据记录条数觉得表格高度
			uniqueId : "", //每一行的唯一标识，一般为主键列
			showToggle : false, //是否显示详细视图和列表视图的切换按钮
			cardView : false, //是否显示详细视图
			detailView : false, //是否显示父子表
			rowStyle: function(row, index) {
				var background = "white";
				background = dropDownOptionLoop(impGredList, row.impGred);
				return {
					css: {color: background}
				}
			},
	        onLoadSuccess: function(result) {
	        	document.getElementById("flowItemsTbRowsCt").innerHTML = result.recordCount;
	        },
	        success: function (dataRes, textStatus, jqXHR) {
	            var result = dataRes.ResultInfo;
	            var debugInfo = dataRes.DebugInfo;
	            if(result != "error"){         
	                 createShowingTable(dataRes);
	            }else{
	                alert("error cause by " + debugInfo);
	            }
	        },
			columns : [
		 	 {
		         field : '',
				 title : '操作',
			 	 align : 'center',
	             valign: 'middle',
	             formatter : function(value, row, index) {
					 return formatterFlowDetail(value, row, index);
				 }
          },
          {
				field : 'itemNo',
				title : '事项流水号',
				align : 'center',
	            valign: 'middle',
				sortable : true
			},
			{
				field : 'regSerial',
				title : '登记流水',
				align : 'center',
	            valign: 'middle',
				sortable : true
			},{
				field : 'busiType',
				title : '业务类型',
				align : 'center',
	            valign: 'middle',
				formatter : function(value, rec) {
					return dropDownOptionLoop(busiTypeList, value);
				}
			},
			{
				field : 'takeChannel',
				title : '订阅频道',
				align : 'center',
	            valign: 'middle'
			},
			{
				field : 'itemTitle',
				title : '事项标题',
				align : 'center',
	            valign: 'middle'
			},
			{
				field : 'itemContent',
				title : '事项内容',
				align : 'center',
	            valign: 'middle'
			},
			{
				field : 'busiNo',
				title : '产品编号',
				align : 'center',
	            valign: 'middle'
			},
			{
				field : 'startTime',
				title : '待办开始时间',
				align : 'center',
	            valign: 'middle',
                formatter: function (value, row) {
                    //return formatterJsonTime2String(row.startTime); //把json中时间戳timeStamp转成(yyyy-mm-dd hh:mm:ss)
                	return row.startTime;
                }
			},
			{
				field : 'endTime',
				title : '待办结束时间',
				align : 'center',
	            valign: 'middle',
                formatter: function (value, row) {
                    //return formatterJsonTime2String(row.endTime); //把json中时间戳timeStamp转成(yyyy-mm-dd hh:mm:ss)
                    return row.endTime;
                }
			},
			{
				field : 'itemSource',
				title : '事项来源',
				align : 'center',
	            valign: 'middle',
				formatter : function(value, rec) {
					return dropDownOptionLoop(itemSourceList, value);
				}
			},
			{
				field : 'impGred',
				title : '优先级别',
				align : 'center',
	            valign: 'middle'
				/**
				,cellStyle : function(row, index) {
					var background = "white";
					background = dropDownOptionLoop(impGredList, row);
					return {
						css: {background: background}
					}
				}*/
			},
			{
				field : 'updateTime',
				title : '更新时间',
				align : 'center',
	            valign: 'middle',
				formatter : function(value, row) {
					//return formatterJsonTime2String(row.updateTime); //把json中时间戳timeStamp转成(yyyy-mm-dd hh:mm:ss)
					return row.updateTime;
				}
			},
			{
				field : 'memo',
				title : '备注',
				align : 'center',
	            valign: 'middle'
			},
			{
				field : 'hisHandler',
				title : '历史处理人',
				align : 'center',
	            valign: 'middle'
			},
			{
				field : 'trfUrl',
				title : 'url链接',
				align : 'center',
	            valign: 'middle'
			},
			{
				field : 'trfSysid',
				title : '跳转系统Id',
				align : 'center',
	            valign: 'middle'
			}
			]
		});
	};

	//得到查询的参数
	oTableInit.queryParams = function(params) {
		var data = new Object();
		data.rows = params.limit;
		data.page = params.offset/params.limit + 1;
		data.maxrows = params.limit;
		data.pageindex = params.pageNumber;
		//data.itemNo = $('#itemNoFlSec').val();
		data.itemTitle = trim($('#itemTitleFlSec').val());
		data.itemContent = trim($('#itemContentFlSec').val());
		data.regSerial = $('#regSerialFlSec').val();
		data.startTime = $('#startTimeFlSec').val();
		data.endTime = trim($('#endTimeFlSec').val());
		data.hisHandler = trim($('#hisHandlerFlSec').val());
		data.itemSource = $('#itemSourceFlSec').val();
		data.remoteServiceId = '210002';
		data.findType = "P";
		data.isNeedPage = "true";
		data.serviceId="remoteService";
    	data.userNo = $('#userNo').val();
		return data;
	};
	return oTableInit;
};

//把Json中的日期（时间戳timeStamp）转成指定格式(yyyy-mm-dd hh:mm:ss)
function formatterJsonTime2String(timeStamp){ 
	 var datetime = new Date();
	 datetime.setTime(timeStamp);
	 var year=datetime.getFullYear();
	 //月份重0开始，所以要加1，当小于10月时，为了显示2位的月份，所以补0
	 var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
	 var date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
	 var hour = datetime.getHours()< 10 ? "0" + datetime.getHours() : datetime.getHours();
	 var minute = datetime.getMinutes()< 10 ? "0" + datetime.getMinutes() : datetime.getMinutes();
	 var second = datetime.getSeconds()< 10 ? "0" + datetime.getSeconds() : datetime.getSeconds();
	 return year + "-" + month + "-" + date+" "+hour+":"+minute+":"+second;
}

openDatePicker = function(id){
    $('#'+id).datepicker('show');
}
